package com.sdut.material.controller;


import com.sdut.material.service.IBuyOrderService;
import com.sdut.material.util.JSONResult;
import com.sdut.material.util.LayUITableResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Yu
 * @since 2022-04-20
 */
@Controller
@RequestMapping("/buyOrder")
public class BuyOrderController {
    @Autowired
    private IBuyOrderService buyOrderService;
    @RequestMapping("/insert")
    @ResponseBody
    public JSONResult insert(Integer materialId, Integer supplierId,Integer demandCount) {
//        System.out.println("进入这个方法了");
//        System.out.println(materialId);
//        System.out.println(supplierId);
//        System.out.println(demandCount);
        buyOrderService.insert(materialId,supplierId,demandCount);
        return JSONResult.ok("添加成功");
    }
    @RequestMapping("/getBuyOrderListPage")
    public String getBuyOrderListPage() {
        return "buyOrder/buyOrder_list";
    }
    @RequestMapping("/selectByPage")
    @ResponseBody
    public LayUITableResult selectByPage(Long page,Long limit) {
        return buyOrderService.selectByPage(page,limit);
    }
    @RequestMapping("/deleteById")
    @ResponseBody
    public JSONResult deleteById(Integer buyOrderId) {
        buyOrderService.deleteById(buyOrderId);
        return JSONResult.ok("删除成功");
    }
    @RequestMapping("/deleteAll")
    @ResponseBody
    public JSONResult deleteAll(String ids) {
        String[] idArray = ids.split(",");
        for (String buyOrderId : idArray) {
            buyOrderService.deleteById(Integer.parseInt(buyOrderId));
        }
        return JSONResult.ok("删除成功");
    }
    @RequestMapping("/check")
    @ResponseBody
    public JSONResult check(Integer buyOrderId) {
        return buyOrderService.check(buyOrderId);
    }
}

